﻿using System.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace NNTH
{
    public partial class fKeHoachHT : DevExpress.XtraEditors.XtraForm
    {
        public fKeHoachHT()
        {
            InitializeComponent();
        }
        Data.QLTTNNTHEntities db = new Data.QLTTNNTHEntities();
        private void btnThem_Click(object sender, EventArgs e)
        {
            keHoachHTBindingSource.AddNew();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            keHoachHTBindingSource.RemoveCurrent();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            db.SaveChanges();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void keHoachHTBindingSource_AddingNew(object sender, AddingNewEventArgs e)
        {
            if (searchLookUpEdit1.EditValue!=null)
            {
                var a = (string)searchLookUpEdit1.EditValue;
                e.NewObject = new Data.KeHoachHT()
                {
                    MaLop= a,
                    NgayThi1= DateTime.Now.AddDays(30),
                    NgayThi2 = DateTime.Now.AddDays(37),
                    NamHoc = DateTime.Now.Year
                };
            }
            else
            {
                e.NewObject = new Data.KeHoachHT()
                {
                    NgayThi1 = DateTime.Now.AddDays(30),
                    NgayThi2 = DateTime.Now.AddDays(37), NamHoc =DateTime.Now.Year
                };
            }
            
        }

        private void searchLookUpEdit1_EditValueChanged(object sender, EventArgs e)
        {
            var a = (string)searchLookUpEdit1.EditValue;
            this.keHoachHTBindingSource.DataSource = db.KeHoachHT.Where(p => p.MaLop == a);
        }

        private void fKeHoachHT_Load(object sender, EventArgs e)
        {
            this.lopHocBindingSource.DataSource = this.lopHocBindingSource1.DataSource = db.LopHoc;
            this.monHocBindingSource.DataSource = db.MonHoc;
            this.keHoachHTBindingSource.DataSource = db.KeHoachHT;//.Where(p => p.ID == -1);
        }
    }
}